//
//  BSXPFIconButton.m
//  BaiSiBuDeJie
//
//  Created by XPF on 16/8/30.
//  Copyright © 2016年 tsaievan. All rights reserved.
//

#import "BSXPFIconButton.h"

@interface BSXPFIconButton ()

@property (weak,nonatomic) UIImageView *iconView;

@property (weak,nonatomic) UILabel *nameLab;

@property (weak,nonatomic) UILabel *timeLab;
@end

@implementation BSXPFIconButton

- (instancetype)init
{
    self = [super init];
    if (self) {
        
        UIImageView *iconView = [[UIImageView alloc] init];
        self.iconView = iconView;
        [self addSubview:iconView];
        
        UILabel *nameLab = [[UILabel alloc] init];
        self.nameLab = nameLab;
        [self addSubview:nameLab];
        self.nameLab.font = [UIFont systemFontOfSize:14];
        self.nameLab.textColor = [UIColor grayColor];
        
        
        UILabel *timeLab = [[UILabel alloc] init];
        self.timeLab = timeLab;
        [self addSubview:timeLab];
        self.timeLab.font = [UIFont systemFontOfSize:13];
        self.timeLab.textColor = [UIColor grayColor];
        
    }
    
    [self setNeedsUpdateConstraints];
    return self;
}

- (void)updateConstraints{
    
    __weak typeof (self)weakSelf = self;
    
    [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.bottom.left.equalTo(weakSelf).offset(0);
        
        make.width.equalTo(weakSelf.mas_height);
        
    }];
    
    [self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(weakSelf.iconView.mas_right).offset(0);
        
//        make.height.equalTo(weakSelf.mas_height);
        
        make.top.right.equalTo(weakSelf).offset(0);
        
    }];
    
    [self.timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(weakSelf.iconView.mas_right).offset(0);
        
        make.top.equalTo(weakSelf.nameLab.mas_bottom).offset(0);
        
        make.bottom.right.equalTo(weakSelf).offset(0);
        
        make.height.equalTo(weakSelf.nameLab.mas_height);
        
        
    }];
    
    
    
    [super updateConstraints];
    
}

-(void)layoutSubviews{
    [super layoutSubviews];
    
    self.iconView.layer.cornerRadius = self.iconView.bounds.size.width * 0.5;
    self.iconView.layer.masksToBounds = YES;
}

-(void)setHeader:(NSString *)header{
    
    _header = header;
    
    NSURL *url = [NSURL URLWithString:header];
    

    
    [self.iconView sd_setImageWithURL:url];
    
}
-(void)setName:(NSString *)name{
    
    _name = name;
    
    self.nameLab.text = name;
    
}
-(void)setPasstime:(NSString *)passtime{
    
    self.timeLab.text = passtime;
    
}



@end
